{% extends "admin_base.html" %}

{% block title %}Edit Post - Admin - Blog{% endblock %}


{% block head %}
   {{ super() }}
    <link rel="stylesheet" href="{{ uri_for_static('/static/css/wmd.css') }}" />
    <link rel="stylesheet" href="{{ uri_for_static('/static/css/prettify.css') }}" />
{% endblock %}

{% block page_content %}
<form action="{{ uri_for('admin-post') }}{% if post %}?id={{ post.get_id() }}{% endif %}" method="POST" class="yui3-form">
<div class="yui3-g">
 <div class="yui3-u-3-4">
<fieldset>
  <legend>Create New Post</legend>

  <label for="inp_title">Title: </label>
  <input type="text" id="inp_title" name="title" value="{{ post.title }}" placeholer="Title" />
  <div class="wmd-panel">
    <div id="wmd-button-bar"></div>
    <textarea class="wmd-input" id="wmd-input" name="content">{{ post.content | safe }}</textarea>
 </div>
   <label for="ta_abstract">Abstract: </label>
  <textarea class="wmd-input" id="ta_abstract" name="abstract">{{ post.abstract | safe }}</textarea>

 <label for="publish">
     <input type="checkbox" id="publish" name="publish" {% if post.published %}checked="yes"{% endif %}>Publish
 </label>
 


 <button type="submit" class="yui3-button notice">Save</button>
 <div id="wmd-preview" class="wmd-panel wmd-preview"></div>
</fieldset>
</div>
<div class="yui3-u-1-4">
   <label for="inp-selcat">Category:</label>
   <select id="inp-selcat" name="category">
       {% for c in category_list %}
       <option value="{{ c.name }}" {% if post and  post.category and  c.name == post.category.name %}selected{% endif %}>{{ c.label }}</option>
       {% endfor %}
   </select><br/>
   <label for="inp-tags">Tags:</label>
   <input type="text" id="inp-tags" name="tags" value="{% if post %}{{ post.get_tags_str() }}{% endif %}" />
</div>
</div>
</form>
<ul id="uploaded-files">

</ul>
{% if post %}
<form id="file-upload-form" method="POST" action="{{ upload_url }}" enctype="multipart/form-data">
            <input type="hidden" id="hd_postid" name="post_id" value="{{ post.get_id() }}"/>
            <label for="inp_file">File: </label>
            <input type="file" id="inp_file" name="file" />
            <label for="inp_title">Title: </label>
            <input type="text" id="inp_title" name="file_title" value="" placeholer="File Title" />
            <button id="upload-file-button" type="submit" class="yui3-button">Upload</button>
</form>
{% else %}
<div>Can only upload file for saved Post. Please save post firstly!</div>
{% endif %}
{% endblock %}

{% block js %}
    <script type="text/javascript" src="{{ uri_for_static('/static/js/Markdown.Converter.js') }}"></script>
    <script type="text/javascript" src="{{ uri_for_static('/static/js/Markdown.Sanitizer.js') }}"></script>
    <script type="text/javascript" src="{{ uri_for_static('/static/js/Markdown.Editor.js') }}"></script>
    <script type="text/javascript" src="{{ uri_for_static('/static/js/prettify.js') }}"></script>
    <script type="text/javascript" src="{{ uri_for_static('/static/js/main.js') }}"></script>
    <script type="text/javascript" src="{{ uri_for_static('/static/js/editor.js') }}"></script>
{% endblock %}

